@{ViewBag.Title = " UnidadMilitar ";
  Layout = "../Shared/_LayoutJtable.cshtml";
  }
<div class="filtering"><form>
<label>Introduzca texto para filtrar: <input type="text" name="filter" id="filter" /></label>
<button type="submit" id="LoadRecordsButton" class="button medium orange" >Buscar Coincidencias</button>
</form></div>
<div id="MyTableContainer"></div>
<script type="text/javascript">
     $(document).ready(function () {
     $('#MyTableContainer').jtable({
         title: 'UnidadMilitar',
         paging: true,
         pageSize: 40,
         sorting: true,
         defaultSorting: 'Id ASC',
         actions: {
             listAction: '@Url.Action("JSONPagedListByFilter")',
             deleteAction: '@Url.Action("JSONDelete")',
             updateAction: '@Url.Action("JSONUpdate")',
             createAction: '@Url.Action("JSONCreate")'
         },
         fields:
         {
          Id: {
                 key: true,
                 create: false,
                 edit: false,
                 list: false
             }
             ,
             Guid: {
                 type: 'hidden'
             }
             ,
             Codigo: {
                 title:'Codigo',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             Nombre: {
                 title:'Nombre',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             NombreLegal: {
                 title:'NombreLegal',
                 create: true,
                 edit: true,
                 list: false,
                 sorting: false
             }
             ,
             Direccion: {
                 title:'Direccion',
                 create: true,
                 edit: true,
                 list: false,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             Telefonos: {
                 title:'Telefonos',
                 create: true,
                 edit: true,
                 list: false,
                 sorting: false
             }
             ,
             Email: {
                 title:'Email',
                 create: true,
                 edit: true,
                 list: false,
                 sorting: false
             }
             ,
             Descripcion: {
                 title:'Descripcion',
                 create: true,
                 edit: true,
                 list: false,
                 sorting: false,
                 type:'textarea'
             }
             ,
             Latitud: {
                 title:'Latitud',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             Longitud: {
                 title:'Longitud',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             AceptaEntradas: {
                 title:'AceptaEntradas',
                 create: true,
                 edit: true,
                 list: true,
                 type: 'checkbox',
                 values:{'false':'Desactivado','true':'Activado'},
                 sorting: false
             }
             ,
             CategoriaUnidadId_FK:{
                 title : 'CategoriaUnidad',
                 create : true,
                 edit : true,
                 list : true,
                 options : '@Url.Action("../CategoriaUnidad/JSONGetElementsForDropDownList")'
             }
             ,
             RegionId_FK:{
                 title : 'DUA_Region',
                 create : true,
                 edit : true,
                 list : true,
                 options : '@Url.Action("../Region/JSONGetElementsForDropDownList")'
             }
             ,
             FuerzaId_FK:{
                 title : 'Fuerza',
                 create : true,
                 edit : true,
                 list : false,
                 options : '@Url.Action("../Fuerza/JSONGetElementsForDropDownList")'
             }
             ,
             TipoUnidadId_FK:{
                 title : 'TipoUnidad',
                 create : true,
                 edit : true,
                 list : true,
                 options : '@Url.Action("../TipoUnidad/JSONGetElementsForDropDownList")'
             }
             ,
             UnidadPadreId_FK:{
                 title : 'Depende de',
                 create : true,
                 edit : true,
                 list : false,
                 options : '@Url.Action("../UnidadMilitar/JSONGetUnidadesPadres")'
             },
             Foto:
             {
                 title: 'Logo',
                 width: '50px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (tempData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../content/images/comment.png" title="Logo" />');
                     $img.click(function () {
                         //window.open('../Media/Cargar?guid=' + tempData.record.Guid);
                         location.href = '../Media/Cargar?guid=' + tempData.record.Guid + '&titulo=' + tempData.record.Nombre;
                     });

                     return $img;
                 }
             },

             Requerimiento: {
                 title: 'Personal',
                 width: '1%',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (umData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../content/images/comment.png" title="Requerimientos de Personal" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'REQUERIMIENTOS DE : ' + umData.record.Nombre,
                                        actions: {
                                            listAction: '@Url.Action("../RequerimientoConfig/GetPorUnidadGuid")?guid=' + umData.record.Guid,
                                            deleteAction: '@Url.Action("../RequerimientoConfig/JSONDelete")',
                                            updateAction: '@Url.Action("../RequerimientoConfig/JSONUpdate")',
                                            createAction: '@Url.Action("../RequerimientoConfig/JSONCreate")'
                                        },
                                        fields: {
                                            UnidadMilitarId_FK: {
                                                type: 'hidden',
                                                defaultValue: umData.record.Id
                                            },
                                            Id: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            }
                                            ,
                                            Guid: {
                                                type: 'hidden'
                                            }

                                            ,
                                            NumPersonas: {
                                                title: 'NumPersonas',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            AutorizadoPor: {
                                                type: 'hidden'
                                            }
                                            ,
                                            PromocionDesde: {
                                                title: 'PromocionDesde',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'mm-dd-yy',
                                                sorting: false
                                            }
                                            ,
                                            PromocionHasta: {
                                                title: 'PromocionHasta',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'mm-dd-yy',
                                                sorting: false
                                            }
                                            ,
                                            ArmaId_FK: {
                                                title: 'Arma',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Arma/JSONGetElementsForDropDownList")'
                                            }
                                            ,
                                            EspecialidadId_FK: {
                                                title: 'Especialidad',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Especialidad/JSONGetElementsForDropDownList")'
                                            }
                                            ,
                                            GestionId_FK: {
                                                type: 'hidden'
                                             }
                                             ,
                                            GradoId_FK: {
                                                title: 'Grado',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Grado/JSONGetElementsForDropDownList")'
                                             }
                                             ,
                                            TipoCargoComandoId_FK: {
                                                title: 'TipoCargoComando',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../TipoCargoComando/JSONGetElementsForDropDownList")'
                                            }


                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
             },

             Requer:
             {
                 title: 'Requer.',
                 width: '50px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (tempData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../content/images/comment.png" title="Reporte Requerimiento de la Gestion Actual" />');
                     $img.click(function () {
                         window.open('../Reporte/RequerimientoConfig?unidadesIds=' + tempData.record.Id);
                     });

                     return $img;
                 }
             }


},
formCreated: function (event, data) {data.form.validationEngine();},
formSubmitting: function (event, data) {return data.form.validationEngine('validate');},
formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
});
$('#LoadRecordsButton').click(function (e) {e.preventDefault();$('#MyTableContainer').jtable('load', {filter: $('#filter').val()});});
$('#LoadRecordsButton').click();
});
</script>

